﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AskiNowclass;
using System.Data;
using System.Configuration;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

public partial class videohistory : System.Web.UI.Page
{
    

    protected string orderid = "";
    protected string userid = "";
    protected string touserid = "";
    protected string utype = "";//0学生1老师

    protected string studentid = "";
    protected string teacherid = "";

    protected string startdate = "";
    protected string subname = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        

        #region 缓存cookie判断是否存在
        userid=WebHelper.CookieReadOne("userid");

        if (userid == "") {

            WebHelper.Alert("Please login first");
            WebHelper.GoBack();
        }

        
        #endregion

        #region 订单id
        orderid = WebHelper.GetStringByFilter("orderid");

        if (orderid == "") {

            WebHelper.Alert("Invalid string of orderid");
            WebHelper.GoBack();
        }
        #endregion


        

               #region 订单状态判断 必须为50

        
            try
            {
                #region 链接消息服务器，从服务器再判断
                string messageurl = ConfigurationManager.AppSettings["MessageUrl"].ToString();

                string restr = WebHelper.GetHtmlGet(messageurl + "/api/orders/" + orderid + "");
               

                JObject json = JObject.Parse(restr);



                if (json["returnvalue"].ToString().Equals("True"))
                {
                    JArray jsondata = (JArray)JsonConvert.DeserializeObject(json["data"].ToString());



                    if (jsondata[0]["orderState"].ToString().Trim().Equals("60"))
                    { 
                        // 上课中
                        startdate = jsondata[0]["startTime"].ToString().Trim();
                        subname = jsondata[0]["subjectName"].ToString().Trim();
                        teacherid = jsondata[0]["teacherId"].ToString().Trim();
                        studentid = jsondata[0]["studentId"].ToString().Trim();

                         

                            if (teacherid.Equals(userid))
                            {

                                touserid = studentid;
                                utype = "1";
                     
                            }
                            else
                            {

                                touserid = teacherid;
                                utype = "0";
                    
                            }
                         
                         
                    }
                    else
                    { 
                        // 课程结束
                        WebHelper.Alert("Class is over, orderstate");
                        WebHelper.GoBack();
                    }
                }
                else
                { 
                    WebHelper.Alert("system error");
                    WebHelper.GoBack();

                }

                #endregion

            }
            catch {
                WebHelper.Alert("message server error");
                WebHelper.GoBack();
            }
         

       
        #endregion
    }
}